﻿using FakeItEasy;
using NJabber.Stream.Elements;
using NUnit.Framework;
using System;
namespace NJabber.Client
{
    [TestFixture]
    public class MessageHandlerTests
    {
        private StandartClientRuntime runtime;
        private IEventMediator mediator;
        private MessageStanzaHandler handler;

        [SetUp]
        public void Setup()
        {
            handler = new MessageStanzaHandler();
            runtime = A.Fake<StandartClientRuntime>();
            mediator = A.Fake<IEventMediator>();
            runtime.Event = mediator;            
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ProcessStanza_RuntimeParameterIsNull_ThrowsException()
        {
            handler.ProcessStanza(null, A.Dummy<MessageStanza>());
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ProcessStanza_StanzaParameterIsNull_ThrowsException()
        {
            handler.ProcessStanza(A.Dummy<StandartClientRuntime>(), null);
        }

        [Test]
        public void ProcessStanza_AnyMessageStanza_CallsOnMessageStanza()
        {
            MessageStanza stanza = new MessageStanza();

            handler.ProcessStanza(runtime, stanza);

            A.CallTo(() => mediator.OnMessageStanza(stanza)).MustHaveHappened();
        }
    }
}
